import {getIsInulaActEnvironment, setInulaActEnvironment} from './act-compat'
import {cleanup} from './pure'

if (typeof process === 'undefined' || !process.env?.OIL_SKIP_AUTO_CLEANUP) {
  if (typeof afterEach === 'function') {
    afterEach(() => {
      cleanup()
    })
  } else if (typeof teardown === 'function') {
    teardown(() => {
      cleanup()
    })
  }

  if (typeof beforeAll === 'function' && typeof afterAll === 'function') {
    let previousIsInulaActEnvironment = getIsInulaActEnvironment()
    beforeAll(() => {
      previousIsInulaActEnvironment = getIsInulaActEnvironment()
      setInulaActEnvironment(true)
    })

    afterAll(() => {
      setInulaActEnvironment(previousIsInulaActEnvironment)
    })
  }
}

export * from './pure'